<?php
/**
 * @version        $Id: admin_email_ok.php 2014年8月20日Z yeshili $
 * @package        YeshiliCMS.Admin
 * @copyright      Copyright (c) 2014 - 2050, YeshiliCMS, Inc.
 * @license        http://help.****.com/YeshiliCMS/help.html
 * @link           http://www.****.com
 */
include '../inc/config.php';
require 'admin_session.php'; 
$act = $_GET['act'];
$id =getvar('id');
$mid        =$_SESSION['id'];
$title 		=getvar('title');
$content	=getvar("content");
if($act=='add'){
	$record = array(
		'mid'		=>$mid,
		'title'		=>$title,
		'content'	=>$content,
		'datetime'	=>date("y-m-d H-i-s")
	);
	$db->insert($GLOBALS[dbprefix].'email',$record);
	get_upfiles('email',$mid,'eid',$title);
	get_record('【邮件模版】'.$title,'add');
	echo "<script>alert('添加成功!');window.location='admin_email.php';</script>";
}
if ($act=='mod'){
	$record = array(
		'mid'		=>$mid,
		'title'		=>$title,
		'content'	=>$content
	);
	$db->update($GLOBALS[dbprefix].'email',$record,'id='.$id);
	get_upfiles('email',$mid,'eid',$title);
	get_record('【邮件模版】'.$title,'mod');
	echo "<script>alert('修改成功!');window.location='admin_email.php';</script>";
}

//删除
if ($act=='del') {
	get_delfile1('eid',$id);
	get_record('【邮件模版】'.get_field('email','title','id',$id),'del');
	$db->delete($GLOBALS[dbprefix].'email','id='.$id);
	echo "<script>alert('删除成功!');history.go(-1);</script>";
}

//多选删除
if ($act=='delcheck') {
	$arr=array();
	$arr =$_POST['ck'];
	if(!empty($arr)){
	  foreach ($arr as $v){
		  get_delfile1('eid',$v);
		  get_record('【邮件模版】'.get_field('email','title','id',$v),'del');
		  $db->delete($GLOBALS[dbprefix].'email',"id=".$v);
	  }
	  echo "<script>alert('删除成功!');history.go(-1);</script>";
	}else
	{
	  echo "<script>alert('删除失败!');history.go(-1);</script>";
	}
}
?>
